#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    pid_t id = fork();
    if (id > 0)
    {
        //parent
        int status = 0;
        pid_t rid = wait(&status);
        if (rid > 0)
        {
            if (WIFEXITED(status))
            {
                 printf("wait sucess!!rid:%d, exit_code:%d\n", rid, WEXITSTATUS(status));
            }
        }
        else
        {
            printf("wait failed\n");
        }
    }
    else if (id == 0)
    {
        //child
       int cnt = 5;
       while(cnt--)
       {
           printf("I am child, pid:%d, ppid:%d\n", getpid(), getppid());
            sleep(1);
       }
       exit(123);
    }
    return 0;
}
